package com.zc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zc.mapper.CustomerMapper;
import com.zc.pojo.Customer;
import com.zc.service.CustomerService;
import com.zc.utils.ZCProperries;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private CustomerMapper customerMapper;

    @Autowired
    private ZCProperries zcProperries;


    @Override
    public PageInfo<Customer> queryByPage(String realName, String phone, Integer page, Integer limit) {

        Map<String, Object> map = new HashMap<>();
        map.put("realName", realName);
        map.put("phone", phone);

        PageHelper.startPage(page, limit);
        List<Customer> stuTestList = customerMapper.listCustomer(map);
        PageInfo<Customer> pageInfo = new PageInfo<Customer>(stuTestList);

        return pageInfo;
    }

    @Override
    public void save(Customer customer) {
        customer.setDeleted(new Byte("0"));
        customer.setCreateTime(new Date());
        customerMapper.insert(customer);
    }

    @Override
    public Customer getById(Long customerId) {
        return customerMapper.selectByPrimaryKey(customerId);
    }

    @Override
    public void update(Customer customer) {
        customer.setDeleted(new Byte("0"));
        customer.setCreateTime(new Date());
        customer.setModifiedTime(new Date());
        customerMapper.updateByPrimaryKey(customer);
    }

    @Override
    public void delete(Long customerId) {
        customerMapper.deleteByPrimaryKey(customerId);
    }

    @Override
    public void logicalDelete(Long accountId) {
        Customer customer = new Customer();
        customer.setDeleted(new Byte("1"));
        customer.setModifiedTime(new Date());
        customer.setCustomerId(accountId);
        customerMapper.logicalDelete(customer);
    }

}